﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLBH.DTO;
using QLBH.DataModel;
using QLBH.Model.Controller;

namespace Module.Category.BL
{
    public class ProviderManagementBL
    {
        private static ProviderManagementBL instance;

        public static ProviderManagementBL Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new ProviderManagementBL();
                }
                return instance;
            }
        }
        public ProviderManagementBL()
        {

        }
        /// <summary>
        /// Get all providers from database
        /// </summary>
        /// <returns></returns>
        public IList<NhaCCDTO> GetAllProviders()
        {
            IList<NhaCC> providers = ProviderController.Instance.GetAll().ToList();
            return NhaCCAssembler.ToDTOs(providers).ToList();
        }        
        /// <summary>
        /// Update Provider
        /// </summary>
        /// <param name="updateProvider"></param>
        /// <returns></returns>
        public bool UpdateProvider(NhaCCDTO updateProvider)
        {
            try
            {
                NhaCC provider = NhaCCAssembler.ToEntity(updateProvider);
                ProviderController.Instance.Edit(provider);
                return true;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Delete providers
        /// </summary>
        /// <param name="listProviders"></param>
        /// <returns></returns>
        public void DeleteProviders(IList<NhaCCDTO> listProviders)
        {
            try
            {
                ICollection<NhaCC> providers = NhaCCAssembler.ToEntities(listProviders);
                ProviderController.Instance.Deletes(providers.ToList());

            }
            catch (System.Exception ex)
            {
                throw ex;
            }


        }
    }
}
